package com.wuzf.navigation_test.view;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.wuzf.navigation_test.R;

public class EmptyView extends LinearLayout {

    private ImageView emptyImage;
    private TextView textView;
    private Button button;

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public EmptyView(@NonNull Context context) {
        this(context, null);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public EmptyView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public EmptyView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }


    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public EmptyView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int style) {
        super(context, attrs, defStyleAttr, style);
        setOrientation(VERTICAL);
        setGravity(Gravity.CENTER);
        LayoutInflater.from(context).inflate(R.layout.empty_page, this, true);

        emptyImage = findViewById(R.id.emptyImage);
        textView = findViewById(R.id.emptyTitle);
        button = findViewById(R.id.emptyButton);
    }

    public void setImage(@DrawableRes int res) {
        this.emptyImage.setImageResource(res);
    }

    public void setTitle(String title) {
        this.textView.setText(title);
    }

    public void setButton(String name, View.OnClickListener listener) {
        this.button.setText(name);
        this.button.setOnClickListener(listener);
    }
}
